package util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class Util {
    
    private static SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    public static boolean isNull(String str) {
         return (str == null || str.isEmpty());
    }
    
    public static boolean isNull(Object obj) {
        return (obj == null);
    }
    
    
    
    public static boolean isNull(Integer integer) {
        return (integer == null || integer.intValue() == 0);
    }
    
    public static boolean isNull(Long valor) {
        return (valor == null || valor.intValue() == 0);
    }
    
    public static String getDateToString(Date date) {
        return dateFormat.format(date);
    }
    
    public static String getCalendarToString(Calendar calendar) {
        
        
          if (calendar == null) {
            return null;
          }
          calendar.setLenient(false);
          return getDateToString(calendar.getTime());
    }
    
    
    public static Calendar getCalendar(String data)  {
        try {
        Calendar calendar = Calendar.getInstance();
        Date date = dateFormat.parse(data);
        dateFormat.setLenient(false);
        calendar.setTime(date);
        return calendar;
        } catch(ParseException e) {
            return null;
        }
         
          
    }
    
    public static List<Integer> listYears(){
    	Integer currentYear = Calendar.getInstance().get(Calendar.YEAR);
    	List<Integer> listYears = new ArrayList<Integer>();
    	
    	for (int i = currentYear; i >= Constantes.ANO_INICIO; i--) {
    		listYears.add(i);
		}    	
    	return listYears;    	
    }
    
    
    
    
}
